package com.hotel.wallet.controller;


import cn.hutool.core.convert.NumberWithFormat;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hotel.common.config.SystemConfig;
import com.hotel.common.util.JwtUtil;
import com.hotel.common.vo.R;
import com.hotel.user.entity.UserCashback;
import com.hotel.user.entity.UserCashbackLog;
import com.hotel.wallet.mapper.UserCashbackMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhy
 * @since 2024-06-18
 */
@RestController
@RequestMapping("user/wallet")
public class UserCashbackController {

    @Autowired
    private UserCashbackMapper userCashbackMapper;


    /**
     * 返现总额展示
     */
    @RequestMapping("/cashBack")
    public R showCashBack(HttpServletRequest request) {

        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        Integer id = ((NumberWithFormat) JwtUtil.parseToken(token, "id")).intValue();

        QueryWrapper<UserCashback> userCashbackQueryWrapper = new QueryWrapper<>();
        userCashbackQueryWrapper.eq("user_id", id);

        UserCashback userCashback = userCashbackMapper.selectOne(userCashbackQueryWrapper);

        if (userCashback == null) {

            return R.fail("未查询到数据");
        }

        return R.ok(userCashback);
    }



}

